<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //数组 
    //数组名 [ 索引] ：索引从0开始
    
    let arr1 =[ 12,4,'abc',false,null,34,,,,,123.34567];
    console.log(arr1[5]);
    console.log(arr1[6]);
    console.log(arr1);
    console.log('----------------');
    console.log(arr1.length);
    console.log('----------------');
    for(let i=0;i<arr1.length;i++){
        console.log(arr1[i]);
    }
    console.log('===================================');

    //数组： 一组数据
    let arr= [45,78,23,457,-78,0];
    console.log(arr[2]); //23
    console.log(arr);  //打印对象 object  (6) [45, 78, 23, 457, -78, 0]

    console.log('------------------');
    //遍历数组
    for (let i=0 ;i<5;i++){
        console.log(arr[i]);
    }

    console.log('--------------------');
    //找出成绩score中的最高分 ，并求平均分数 。score [45,78,89,94,63,55,80,74];
    let score= [45,78,89,94,63,55,80,74];
    let max=score[0],avg,sum=0;

    //最大值
        for(let i=0; i<score.length;i++){
            if(score [i]>max){
                max=score[i];
            }
        sum += score[i];
        } 
        avg=sum/score.length;
        console.log('最大分数'+max);
        console.log('平均分'+avg);

    console.log('--------------');
    console.log(score.length); //长度 8
    //插入
    score[47]=90;
    console.log(score.length);
    console.log(score);

    console.log('----------------------------');
    //删除数组元素 delete 
    //冒泡排序
    let arr2=[1,3,2,6,5,4];
    //两层循环
    for(let i=1;i<arr2.length;i++){
        for(let j=0;j<arr2.length-i;j++){
            if(arr2[j]>arr2[j+1]){
                temp =arr2[j];
                arr2[j]=arr2[j+1];
                arr2[j+1]=temp;
            }

        }
    }
    console.log(arr2);

    console.log('-----------------------');
    //二维数组
    let arr3 = [[1,2,3],[4,5,6],[7,,8,9]];
    console.log(arr3[0]);         // 打印 (3) [1, 2, 3]
    //单个打印 
    console.log(arr3[0][0]);    //1
    console.log(arr3[0][1]);    //2
    console.log(arr3[0][2]);    //3

    console.log('-------------------');
    //循环方式 遍历 二维数组
    for (let i=0;i<arr3.length;i++){
        for(let j=0;j<arr3[i].length;j++){
            console.log(arr3[i][j]);
        }
    }





    
</script>
</html>